package com.ymatou.iapi.livebuyer.testcase;

import java.util.List;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.livebuyer.parameter.ShutUpInLiveRoomBean;
import com.ymatou.iapi.livebuyer.service.ShutUpInLiveRoomCall;
import com.ymatou.iapi.liveseller.parameter.CreateSellerLiveBean;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.LiveRoomCallService;
import com.ymttest.database.model.LiveRoom;
import com.ymttest.database.sqlwapper.LiveRoomWapper;
import com.ymttest.utils.TestDataManager;
/**
*直播间内禁言
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_ShutUpInLiveRoom{
	private static ShutUpInLiveRoomBean shutupinliveroomBean;
	private static ShutUpInLiveRoomCall shutupinliveroomCall;
	LiveRoomWapper liveRoomWapper;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("直播间内禁言");
	}

	@Before
	public void caseUp() {
		shutupinliveroomBean=new ShutUpInLiveRoomBean();
		shutupinliveroomCall=new ShutUpInLiveRoomCall();
		liveRoomWapper=new LiveRoomWapper();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(shutupinliveroomCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ShutUpInLiveRoom_001() {
		Logger.start(true,"直播间内禁言成功");
		try {
			CreateSellerLiveBean initcreatebean = LiveRoomCallService.initCreatesellerliveBean(null);
			initcreatebean.getLiveDto().setGroupId(LiveRoomCallService.CreateGroup("SU"+TestDataManager.getRandomNum(5),initcreatebean.getLiveDto().getUserId()));
			LiveRoom livedto = LiveRoomCallService.CreateSellerLive(initcreatebean);
			int liveid = livedto.getId();
			Integer uid = 1;
			LiveRoomCallService.SellerLiveOnline(liveid, livedto.getUserId());
			LiveRoomCallService.enterGroup(liveid, uid);
			shutupinliveroomBean.setLiveId(liveid);
			shutupinliveroomBean.setSellerId(livedto.getUserId());
			shutupinliveroomBean.setUserId(uid);
			shutupinliveroomCall.setData(shutupinliveroomBean);
			shutupinliveroomCall.callService();		
			Logger.verifyEquals("200", shutupinliveroomCall.getString("code"), "验证code");
			List<Map> templist = liveRoomWapper.selectLivemember(liveid, uid);
			Logger.debug(templist);
			Logger.verifyEquals(1, templist.size(), "验证长度");
			Logger.verifyEquals(1, Integer.valueOf(templist.get(0).get("ShutUp").toString()), "验证ShutUp");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_ShutUpInLiveRoom_002() {
		Logger.start(true,"不输入userid失败");
		try {
			CreateSellerLiveBean initcreatebean = LiveRoomCallService.initCreatesellerliveBean(null);
//			initcreatebean.getLiveDto().setGroupId(LiveRoomCallService.CreateGroup("SU"+TestDataManager.getRandomNum(5),initcreatebean.getLiveDto().getUserId()));
//			LiveRoom livedto = LiveRoomCallService.CreateSellerLive(initcreatebean);
			int sellerid=3383;
			int liveid = 1;
			Integer uid = 1;
			shutupinliveroomBean.setLiveId(liveid);
			shutupinliveroomBean.setSellerId(sellerid);
//			shutupinliveroomBean.setUserId(uid);
			shutupinliveroomCall.setData(shutupinliveroomBean);
			shutupinliveroomCall.callService();		
			Logger.verifyEquals("100", shutupinliveroomCall.getString("code"), "验证code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_ShutUpInLiveRoom_003() {
		Logger.start(true,"不输入sellerid失败");
		try {
			int sellerid=3383;
			int liveid = 1;
			Integer uid = 1;
			shutupinliveroomBean.setLiveId(liveid);
//			shutupinliveroomBean.setSellerId(sellerid);
			shutupinliveroomBean.setUserId(uid);
			shutupinliveroomCall.setData(shutupinliveroomBean);
			shutupinliveroomCall.callService();		
			Logger.verifyEquals("100", shutupinliveroomCall.getString("code"), "验证code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_ShutUpInLiveRoom_004() {
		Logger.start(true,"不输入liveId失败");
		try {
			int sellerid=3383;
			int liveid = 1;
			Integer uid = 1;
//			shutupinliveroomBean.setLiveId(liveid);
			shutupinliveroomBean.setSellerId(sellerid);
			shutupinliveroomBean.setUserId(uid);
			shutupinliveroomCall.setData(shutupinliveroomBean);
			shutupinliveroomCall.callService();		
			Logger.verifyEquals("100", shutupinliveroomCall.getString("code"), "验证code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_ShutUpInLiveRoom_005() {
		Logger.start(true,"输入userid错误失败");
		try {
			int sellerid=3383;
			int liveid = 1;
			Integer uid = 1;
			shutupinliveroomBean.setLiveId(liveid);
			shutupinliveroomBean.setSellerId(sellerid);
			shutupinliveroomBean.setUserId(-1);
			shutupinliveroomCall.setData(shutupinliveroomBean);
			shutupinliveroomCall.callService();		
			Logger.verifyEquals("100", shutupinliveroomCall.getString("code"), "验证code");	
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_ShutUpInLiveRoom_006() {
		Logger.start(true,"输入sellerid错误失败");
		try {
			int sellerid=3383;
			int liveid = 1;
			Integer uid = 1;
			shutupinliveroomBean.setLiveId(liveid);
			shutupinliveroomBean.setSellerId(-1);
			shutupinliveroomBean.setUserId(uid);
			shutupinliveroomCall.setData(shutupinliveroomBean);
			shutupinliveroomCall.callService();		
			Logger.verifyEquals("100", shutupinliveroomCall.getString("code"), "验证code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_ShutUpInLiveRoom_007() {
		Logger.start(true,"输入liveId错误失败");
		try {
			int sellerid=3383;
			int liveid = 1;
			Integer uid = 1;
			shutupinliveroomBean.setLiveId(-1);
			shutupinliveroomBean.setSellerId(sellerid);
			shutupinliveroomBean.setUserId(uid);
			shutupinliveroomCall.setData(shutupinliveroomBean);
			shutupinliveroomCall.callService();		
			Logger.verifyEquals("100", shutupinliveroomCall.getString("code"), "验证code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_ShutUpInLiveRoom_008() {
		Logger.start(true,"直播间内禁言解禁再禁言成功");
		try {
			CreateSellerLiveBean initcreatebean = LiveRoomCallService.initCreatesellerliveBean(null);
			initcreatebean.getLiveDto().setGroupId(LiveRoomCallService.CreateGroup("SU"+TestDataManager.getRandomNum(5),initcreatebean.getLiveDto().getUserId()));
			LiveRoom livedto = LiveRoomCallService.CreateSellerLive(initcreatebean);
			int liveid = livedto.getId();
			Integer uid = 1;
			LiveRoomCallService.SellerLiveOnline(liveid, livedto.getUserId());
			LiveRoomCallService.enterGroup(liveid, uid);
			shutupinliveroomBean.setLiveId(liveid);
			shutupinliveroomBean.setSellerId(livedto.getUserId());
			shutupinliveroomBean.setUserId(uid);
			shutupinliveroomCall.setData(shutupinliveroomBean);
			shutupinliveroomCall.callService();		
			Logger.verifyEquals("200", shutupinliveroomCall.getString("code"), "验证code");
			List<Map> templist = liveRoomWapper.selectLivemember(liveid, uid);
			Logger.debug(templist);
			Logger.verifyEquals(1, templist.size(), "验证长度");
			Logger.verifyEquals(1, Integer.valueOf(templist.get(0).get("ShutUp").toString()), "验证ShutUp");
			
			LiveRoomCallService.CancelShutUpInLiveRoom(liveid, livedto.getUserId(), uid);
			templist = liveRoomWapper.selectLivemember(liveid, uid);
			Logger.debug(templist);
			Logger.verifyEquals(1, templist.size(), "验证长度");
			Logger.verifyEquals(0, Integer.valueOf(templist.get(0).get("ShutUp").toString()), "验证ShutUp");
			
			shutupinliveroomCall.callService();		
			Logger.verifyEquals("200", shutupinliveroomCall.getString("code"), "验证code");
			templist = liveRoomWapper.selectLivemember(liveid, uid);
			Logger.debug(templist);
			Logger.verifyEquals(1, templist.size(), "验证长度");
			Logger.verifyEquals(1, Integer.valueOf(templist.get(0).get("ShutUp").toString()), "验证ShutUp");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ShutUpInLiveRoom_009() {
		Logger.start(true,"直播间内重复禁言成功");
		try {
			CreateSellerLiveBean initcreatebean = LiveRoomCallService.initCreatesellerliveBean(null);
			initcreatebean.getLiveDto().setGroupId(LiveRoomCallService.CreateGroup("SU"+TestDataManager.getRandomNum(5),initcreatebean.getLiveDto().getUserId()));
			LiveRoom livedto = LiveRoomCallService.CreateSellerLive(initcreatebean);
			int liveid = livedto.getId();
			Integer uid = 1;
			LiveRoomCallService.SellerLiveOnline(liveid, livedto.getUserId());
			LiveRoomCallService.enterGroup(liveid, uid);
			shutupinliveroomBean.setLiveId(liveid);
			shutupinliveroomBean.setSellerId(livedto.getUserId());
			shutupinliveroomBean.setUserId(uid);
			shutupinliveroomCall.setData(shutupinliveroomBean);
			shutupinliveroomCall.callService();		
			shutupinliveroomCall.callService();	
			Logger.verifyEquals("200", shutupinliveroomCall.getString("code"), "验证code");
			List<Map> templist = liveRoomWapper.selectLivemember(liveid, uid);
			Logger.debug(templist);
			Logger.verifyEquals(1, templist.size(), "验证长度");
			Logger.verifyEquals(1, Integer.valueOf(templist.get(0).get("ShutUp").toString()), "验证ShutUp");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ShutUpInLiveRoom_010() {
		Logger.start(true,"liveid和sellerid不匹配失败");
		try {
			CreateSellerLiveBean initcreatebean = LiveRoomCallService.initCreatesellerliveBean(null);
			initcreatebean.getLiveDto().setGroupId(LiveRoomCallService.CreateGroup("SU"+TestDataManager.getRandomNum(5),initcreatebean.getLiveDto().getUserId()));
			LiveRoom livedto = LiveRoomCallService.CreateSellerLive(initcreatebean);
			int liveid = livedto.getId();
			Integer uid = 1;
			LiveRoomCallService.SellerLiveOnline(liveid, livedto.getUserId());
			LiveRoomCallService.enterGroup(liveid, uid);
			shutupinliveroomBean.setLiveId(liveid);
			shutupinliveroomBean.setSellerId(livedto.getUserId()-1);
			shutupinliveroomBean.setUserId(uid);
			shutupinliveroomCall.setData(shutupinliveroomBean);
			shutupinliveroomCall.callService();		
			Logger.verifyEquals("400", shutupinliveroomCall.getString("code"), "验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}